﻿<%@ WebHandler Language="C#" Class="SysRose_Add" %>

using System;
using System.Web;
using System.Text;
using Newtonsoft.Json;
public class SysRose_Add : IHttpHandler, System.Web.SessionState.IReadOnlySessionState
{
    
    public void ProcessRequest (HttpContext context) {
 //检验是否登录
        OTS.Common.PageSuccess page = new OTS.Common.PageSuccess();
        if (!OTS.BaseLogin.validataModule(context, (int)OTS.enumSysRight.SysUser))
        {
            page.success = false;
            page.msg = "非法操作！";
        }
        else
        {
            string _rid = context.Request["user.rid"];
            string _username = context.Request["user.username"];
            string _password = context.Request["user.password"];
            string _realname = context.Request["user.realname"];
            string _department = context.Request["user.department"];
            string _qq = context.Request["user.qq"];
            string _email = context.Request["user.email"];
            string _tel = context.Request["user.tel"];
            string _mobilePhone = context.Request["user.mobilePhone"];
            string _state = context.Request["user.state"];
            if (null != _rid && null != _username && null != _password && null != _realname && null != _state  )
            {
                OTS.Model.sys_user model = new OTS.Model.sys_user();
                model.comment = "";
                model.department = _department;
                model.departmentID = 0;
                model.email = _email;
                model.mobilePhone = _mobilePhone;
                model.password = OTS.Common.Help.MD5(_password);
                model.qq = _qq;
                model.realName = _realname;
                model.rid = int.Parse(_rid);
                model.state = int.Parse(_state);
                model.tel = _tel;
                model.userName = _username;
                
                OTS.BLL.SysUserBLL bll = new OTS.BLL.SysUserBLL();
                if (bll.Add(model))
                {
                    page.success = true;
                    page.msg = "添加成功！";
                }
                else
                {
                    page.success = false;
                    page.msg = "往数据库插入值错误！请稍后再试！";
                }
                
            }
            else
            {
                page.success = false;
                page.msg = "参数有误！";

            }

  
        }

        context.Response.ContentType = "application/x-json";
        context.Response.Charset = "utf-8";
        context.Response.Write(JavaScriptConvert.SerializeObject(page));
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}